package cn.bugstack.config;

import cn.bugstack.listener.OrderPaySuccessListener;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.eventbus.EventBus;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @Author: 小新
 * @Date: 2025/3/18 9:07
 * @Description: 微信 token缓存配置类
 * @Version: v1.0
 */

@Configuration
public class GuavaConfig {
    @Bean(name = "weixinAccessToken")
    public Cache<String, String> weixinAccessToken() {
        return CacheBuilder.newBuilder()
                .expireAfterWrite(2, TimeUnit.HOURS)
                .build();
    }

    @Bean(name = "openidToken")
    public Cache<String, String> openidToken() {
        return CacheBuilder.newBuilder()
                .expireAfterWrite(1, TimeUnit.HOURS)
                .build();
    }


    @Bean
    public EventBus eventBusListener(OrderPaySuccessListener orderPaySuccessListener){
        EventBus eventBus=new EventBus();
        eventBus.register(orderPaySuccessListener);
        return eventBus;
    }


}
